/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package ejercicio2;
import java.util.Scanner;

/**
 *
 * @author Alejandro
 */
public class ejercicio13 {
    static void contarCaracteres(String cad,String caracter) {
        int contarLetra = 0;
        String CadOriginal = cad;
        while (cad.indexOf(caracter) != -1) {
            contarLetra++;
            cad = cad.substring(cad.indexOf(caracter)+1);
        }
        System.out.println("Se han encontrado " + contarLetra + " veces la letra \"" + caracter + "\" en la cadena \"" + CadOriginal + "\"");
    }
    public static void main(String[] args)  {
        Scanner reader = new Scanner(System.in);
        String cadena, caracter;
        System.out.print("Introduce cadena: ");
        cadena = reader.nextLine();
        System.out.print("Introduce un caracter: ");
        caracter = reader.nextLine();
        contarCaracteres(cadena,caracter);
    }
}
